#include "UserMgr.h"
#include "CSession.h"

UserMgr::UserMgr()
{

}

UserMgr::~UserMgr()
{
    uid_to_session_.clear();
}
std::shared_ptr<CSession> UserMgr::GetSession(int uid)
{
    std::lock_guard<std::mutex> lock(session_mtx_);
    auto it = uid_to_session_.find(uid);
    if(it!=uid_to_session_.end())
    {
        return it->second;
    }
    return nullptr;
    
}
void UserMgr::SetUserSession(int uid,std::shared_ptr<CSession> session)
{
    std::lock_guard<std::mutex> lock(session_mtx_);
    uid_to_session_[uid] = session;
}

void UserMgr::RemoveUserSession(int uid)
{
    std::lock_guard<std::mutex> lock(session_mtx_);
    uid_to_session_.erase(uid);
}